package com.pioneer.swing.model;

import com.pioneer.dao.*;
import com.pioneer.beans.*;
import javax.swing.table.DefaultTableModel;
import java.util.Vector;
import java.util.List;
import java.util.Iterator;

/**
 * Title:        Pioneer Metals Application
 * Description:
 * Copyright:    Copyright (c) 2001
 * Company:      Pioneer Metals
 * @author Gary Chen
 * @version 1.0
 */

public class AllJobsTable extends DefaultTableModel {
	
	public static final int JOB_QUOTE_NUM =  0;
	public static final int JOB_DATE =  1;
	public static final int JOB_NAME =  2;
	public static final int JOB_STATE =  3;
	public static final int JOB_WHOLESALER =  4;
	public static final int JOB_CONTRACTOR =  5;
	public static final int JOB_STATUS =  6;
	public static final int JOB_SALES_REP =  7;
	public static final int JOB_NOTES =  8;
	
	//public static final int JOB_SHIP_DATE =  7;
	//public static final int JOB_REMARKS =  8;
	private String sortField;
	
	private JobDAO jobDAO;
    public AllJobsTable(JobDAO jobDAO) {
		columnIdentifiers=new Vector();
		columnIdentifiers.add(TableConstants.JOB_QUOTE_NUM);
		columnIdentifiers.add(TableConstants.JOB_DATE);
		columnIdentifiers.add(TableConstants.JOB_NAME);
		columnIdentifiers.add(TableConstants.JOB_STATE);
		columnIdentifiers.add(TableConstants.JOB_WHOLESALER);
		columnIdentifiers.add(TableConstants.JOB_CONTRACTOR);
		columnIdentifiers.add(TableConstants.JOB_STATUS);
		columnIdentifiers.add(TableConstants.JOB_SALES_REP);
		columnIdentifiers.add(TableConstants.JOB_NOTES);		
		this.jobDAO=jobDAO;
		refresh();
    }
	
	public void setSortField(String sortField) {
		this.sortField = sortField;
	}

	public void refresh(){
		try	{
		    List jobs=jobDAO.getJobs(sortField);
			// all rows
			dataVector=new Vector();
			Iterator rows=jobs.iterator();
			//Iterator cols=
			while (rows.hasNext())	{
				Job job=(Job)rows.next();
				Vector row=new Vector();
				row.add(job.getQuoteNum());
				row.add(job.getJobDateString());
				row.add(job.getJobName());
				row.add(job.getState());
				row.add(job.getSupplierName());
				row.add(job.getContractorName());
				row.add(job.getStatus());
				row.add(job.getSalesRep());
				row.add(job.getNotes());				
				dataVector.add(row);
			}
		}
		catch (DataAccessException ex)
		{
			ex.printStackTrace(System.err);
		}
	}

	public boolean isCellEditable(int rowIndex,
                              int columnIndex) {
		return false;
	}

    public static void main(String[] args) {
        //AllManifestsTable allManifestsTable1 = new AllManifestsTable();
    }
}